package com.erp.erp_servers.Purchase.imp;

import com.erp.erp_dao.Purchase.IPurchaseFeedbackDao;
import com.erp.erp_entitys.Purchase.PurchaseFeedback;
import com.erp.erp_entitys.Purchase.QueryPurchaseFeedbackVO;
import com.erp.erp_servers.Purchase.IPurchaseFeedbackService;
import com.erp.utils.DateUtils;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zjk
 * @version 1.0
 * @description
 * @date 2021-06-24 2:33
 */
@Service
public class IPurchaseFeedbackServiceImpl implements IPurchaseFeedbackService {

    private final IPurchaseFeedbackDao purchaseFeedbackDao;

    public IPurchaseFeedbackServiceImpl(IPurchaseFeedbackDao purchaseFeedbackDao) {
        this.purchaseFeedbackDao = purchaseFeedbackDao;
    }

    @Override
    public int insertSelective(PurchaseFeedback record) {
        return purchaseFeedbackDao.insertSelective(record);
    }

    @Override
    public int updateByPrimaryKeySelective(PurchaseFeedback record) {
        return purchaseFeedbackDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public List<QueryPurchaseFeedbackVO> getFeedbackDateByParam(PurchaseFeedback purchaseFeedback) {
        List<PurchaseFeedback> purchaseFeedbackList=purchaseFeedbackDao.findPurchaseFeedbackByPrimaryKey(purchaseFeedback);
        List<QueryPurchaseFeedbackVO> list=new ArrayList<>();
        for (PurchaseFeedback p:purchaseFeedbackList) {
            QueryPurchaseFeedbackVO purchaseFeedbackVO= new QueryPurchaseFeedbackVO();
            BeanUtils.copyProperties(p,purchaseFeedbackVO);
            purchaseFeedbackVO.setActualDeliveryStr(DateUtils.format(p.getActualDeliveryDate(),DateUtils.DATE_PATTERN));
            purchaseFeedbackVO.setFeedbackDeliveryDateStr(DateUtils.format(p.getFeedbackDeliveryDate(),DateUtils.DATE_PATTERN));

            list.add(purchaseFeedbackVO);
        }
        return list;
    }
}
